<?php
require 'db.php';

if (!isset($_GET['id'])) {
    http_response_code(400);
    echo json_encode(['message' => 'Invalid announcement ID']);
    exit;
}

$announcement_id = intval($_GET['id']);

$sql = "SELECT * FROM announcements WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $announcement_id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows === 0) {
    http_response_code(404);
    echo json_encode(['message' => 'Announcement not found']);
} else {
    $announcement = $result->fetch_assoc();
    echo json_encode($announcement);
}

$stmt->close();
$conn->close();
?>
